9d8d8a6c83afe4ba1524da873e3b0e11d31d5271,src/com/owent/xresloader/ProgramOptions.java,ProgramOptions,init,#String[]#,217

Before Change


        }
        catch( ParseException exp ) {
            // oops, something went wrong
            System.err.println(String.format("[ERROR] parsing failed.  reason: \"%s\" failed", exp.getMessage()));

            String script = System.getProperty("java.class.path");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage: java -client -jar " + script + " [options...]", options);
            return -1;
        }

        if (cmd.hasOption('h')) {
            String script = System.getProperty("java.class.path");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(String.format("java -client -jar \"%s\" [options...]", script), get_options_group());
            return 1;
        }

        if (cmd.hasOption('v')) {
            System.out.println(getVersion());
            return 1;
        }

        if (cmd.hasOption("stdin")) {
            enableStdin = true;
        }

        if (cmd.hasOption("disable-empty-list")) {
            enbleEmptyList = false;
        } else if(cmd.hasOption("enable-empty-list")) {
            enbleEmptyList = true;
        }

        // target type
        if (cmd.hasOption('t')) {
            String val = cmd.getOptionValue('t');
            if (val.equalsIgnoreCase("bin")) {
                outType = FileType.BIN;
            } else if (val.equalsIgnoreCase("lua")) {
                outType = FileType.LUA;
            } else if (val.equalsIgnoreCase("msgpack")){
                outType = FileType.MSGPACK;
            } else if (val.equalsIgnoreCase("json")){
                outType = FileType.JSON;
            } else if (val.equalsIgnoreCase("xml")){
                outType = FileType.XML;
            } else if (val.equalsIgnoreCase("js") || val.equalsIgnoreCase("javascript")) {
                outType = FileType.JAVASCRIPT;
            } else {
                System.err.println(String.format("[ERROR] [ERROR] invalid output type ", val));
                return -1;
            }
        }

        // protocol type
        if (cmd.hasOption('p')) {
            String val = cmd.getOptionValue('p');
            if (val.equalsIgnoreCase("protobuf")) {
                protocol = Protocol.PROTOBUF;
            } else if (val.equalsIgnoreCase("capnproto")) {
                protocol = Protocol.CAPNPROTO;
            } else if (val.equalsIgnoreCase("flatbuffer")){
                protocol = Protocol.FLATBUFFER;
            } else {
                System.err.println(String.format("[ERROR] [ERROR] invalid protocol type ", val));
                return -2;
            }
        }

        // protocol file
        protocolFile = cmd.getOptionValue('f', "");
        if (protocolFile.isEmpty()) {
            return 1;
        }

        luaGlobal = cmd.hasOption("lua-global");
        xmlRootName = cmd.getOptionValue("xml-root", xmlRootName);
        javascriptExport = cmd.getOptionValue("javascript-export", javascriptExport);
        javascriptGlobalVar = cmd.getOptionValue("javascript-global", javascriptGlobalVar);

        // output dir
        outputDirectory = cmd.getOptionValue('o', ".");
        // data sorce dir
        dataSourceDirectory = cmd.getOptionValue('d', ".");

        // pretty print
        prettyIndent = Integer.parseInt(cmd.getOptionValue("pretty", "0"));

        // const print
        if (cmd.hasOption('c')) {
            constPrint = cmd.getOptionValue('c');
            return 0;
        }

        // macro source file path
        if (cmd.hasOption('s')) {
            dataSourceFile = cmd.getOptionValue('s');
            int dot_index = dataSourceFile.lastIndexOf('.');

            String name_suffix = dot_index >= 0 && dot_index < dataSourceFile.length() - 1? dataSourceFile.substring(dot_index + 1) : null;
            if (null != name_suffix && (
                    name_suffix.equalsIgnoreCase("xls") ||
                            name_suffix.equalsIgnoreCase("xlsx") ||
                            name_suffix.equalsIgnoreCase("cvs") ||
                            name_suffix.equalsIgnoreCase("xlsm") ||
                            name_suffix.equalsIgnoreCase("ods")
            )) {
                dataSourceType = FileType.EXCEL;

            } else if (null != name_suffix && (
                    name_suffix.equalsIgnoreCase("ini") ||
                    name_suffix.equalsIgnoreCase("cfg") ||
                    name_suffix.equalsIgnoreCase("conf")
            )) {
                dataSourceType = FileType.INI;
            } else if (null != name_suffix && name_suffix.equalsIgnoreCase("json")) {
                dataSourceType = FileType.JSON;
//          } else if (null != name_suffix && name_suffix.equalsIgnoreCase("lua")) {
//              dataSourceType = FileType.LUA;
//          } else if (null != name_suffix && name_suffix.equalsIgnoreCase("xml")) {
//              dataSourceType = FileType.XML;
            }
        } else {
            return 1;
        }

        // macro names
        dataSourceMetas = cmd.getOptionValues('m');

        // rename rules
        if (cmd.hasOption('n')) {
            do {
                String rule_string = cmd.getOptionValue('n');
                rule_string = rule_string.trim();
                if (rule_string.isEmpty()) {
                    System.err.println(String.format("[ERROR] Invalid rename rule %s", rule_string));
                    break;
                }

                String[] groups = rule_string.split(rule_string.substring(0, 1));
                int start_index = 0;
                for (; start_index < groups.length; ++start_index) {
                    if (groups[start_index].isEmpty())
                        continue;
                    break;
                }

                if (groups.length < start_index + 2) {
                    System.err.println(String.format("[ERROR] Invalid rename rule %s", rule_string));
                    break;
                }

                Pattern match_rule = null;
                try {
                    match_rule = Pattern.compile(groups[start_index]);
                } catch (PatternSyntaxException e) {
                    System.err.println(String.format("[ERROR] Invalid rename regex rule %s", groups[start_index]));
                    break;
                }

After Change


        }
        catch( ParseException exp ) {
            // oops, something went wrong
            ProgramOptions.getLoger().error("parsing failed.  reason: \"%s\" failed", exp.getMessage());

            String script = System.getProperty("java.class.path");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp("Usage: java -client -jar " + script + " [options...]", options);
            return -1;
        }

        if (cmd.hasOption('h')) {
            String script = System.getProperty("java.class.path");
            HelpFormatter formatter = new HelpFormatter();
            formatter.printHelp(String.format("java -client -jar \"%s\" [options...]", script), get_options_group());
            return 1;
        }

        if (cmd.hasOption('v')) {
            System.out.println(getVersion());
            return 1;
        }

        if (cmd.hasOption("stdin")) {
            enableStdin = true;
        }

        if (cmd.hasOption("disable-empty-list")) {
            enbleEmptyList = false;
        } else if(cmd.hasOption("enable-empty-list")) {
            enbleEmptyList = true;
        }

        // target type
        if (cmd.hasOption('t')) {
            String val = cmd.getOptionValue('t');
            if (val.equalsIgnoreCase("bin")) {
                outType = FileType.BIN;
            } else if (val.equalsIgnoreCase("lua")) {
                outType = FileType.LUA;
            } else if (val.equalsIgnoreCase("msgpack")){
                outType = FileType.MSGPACK;
            } else if (val.equalsIgnoreCase("json")){
                outType = FileType.JSON;
            } else if (val.equalsIgnoreCase("xml")){
                outType = FileType.XML;
            } else if (val.equalsIgnoreCase("js") || val.equalsIgnoreCase("javascript")) {
                outType = FileType.JAVASCRIPT;
            } else {
                ProgramOptions.getLoger().error("invalid output type ", val);
                return -1;
            }
        }

        // protocol type
        if (cmd.hasOption('p')) {
            String val = cmd.getOptionValue('p');
            if (val.equalsIgnoreCase("protobuf")) {
                protocol = Protocol.PROTOBUF;
            } else if (val.equalsIgnoreCase("capnproto")) {
                protocol = Protocol.CAPNPROTO;
            } else if (val.equalsIgnoreCase("flatbuffer")){
                protocol = Protocol.FLATBUFFER;
            } else {
                ProgramOptions.getLoger().error("invalid protocol type ", val);
                return -2;
            }
        }

        // protocol file
        protocolFile = cmd.getOptionValue('f', "");
        if (protocolFile.isEmpty()) {
            return 1;
        }

        luaGlobal = cmd.hasOption("lua-global");
        xmlRootName = cmd.getOptionValue("xml-root", xmlRootName);
        javascriptExport = cmd.getOptionValue("javascript-export", javascriptExport);
        javascriptGlobalVar = cmd.getOptionValue("javascript-global", javascriptGlobalVar);

        // output dir
        outputDirectory = cmd.getOptionValue('o', ".");
        // data sorce dir
        dataSourceDirectory = cmd.getOptionValue('d', ".");

        // pretty print
        prettyIndent = Integer.parseInt(cmd.getOptionValue("pretty", "0"));

        // const print
        if (cmd.hasOption('c')) {
            constPrint = cmd.getOptionValue('c');
            return 0;
        }

        // macro source file path
        if (cmd.hasOption('s')) {
            dataSourceFile = cmd.getOptionValue('s');
            int dot_index = dataSourceFile.lastIndexOf('.');

            String name_suffix = dot_index >= 0 && dot_index < dataSourceFile.length() - 1? dataSourceFile.substring(dot_index + 1) : null;
            if (null != name_suffix && (
                    name_suffix.equalsIgnoreCase("xls") ||
                            name_suffix.equalsIgnoreCase("xlsx") ||
                            name_suffix.equalsIgnoreCase("cvs") ||
                            name_suffix.equalsIgnoreCase("xlsm") ||
                            name_suffix.equalsIgnoreCase("ods")
            )) {
                dataSourceType = FileType.EXCEL;

            } else if (null != name_suffix && (
                    name_suffix.equalsIgnoreCase("ini") ||
                    name_suffix.equalsIgnoreCase("cfg") ||
                    name_suffix.equalsIgnoreCase("conf")
            )) {
                dataSourceType = FileType.INI;
            } else if (null != name_suffix && name_suffix.equalsIgnoreCase("json")) {
                dataSourceType = FileType.JSON;
//          } else if (null != name_suffix && name_suffix.equalsIgnoreCase("lua")) {
//              dataSourceType = FileType.LUA;
//          } else if (null != name_suffix && name_suffix.equalsIgnoreCase("xml")) {
//              dataSourceType = FileType.XML;
            }
        } else {
            return 1;
        }

        // macro names
        dataSourceMetas = cmd.getOptionValues('m');

        // rename rules
        if (cmd.hasOption('n')) {
            do {
                String rule_string = cmd.getOptionValue('n');
                rule_string = rule_string.trim();
                if (rule_string.isEmpty()) {
                    ProgramOptions.getLoger().error("Invalid rename rule %s", rule_string);
                    break;
                }

                String[] groups = rule_string.split(rule_string.substring(0, 1));
                int start_index = 0;
                for (; start_index < groups.length; ++start_index) {
                    if (groups[start_index].isEmpty())
                        continue;
                    break;
                }

                if (groups.length < start_index + 2) {
                    ProgramOptions.getLoger().error("Invalid rename rule %s", rule_string);
                    break;
                }

                Pattern match_rule = null;
                try {
                    match_rule = Pattern.compile(groups[start_index]);
                } catch (PatternSyntaxException e) {
                    ProgramOptions.getLoger().error("Invalid rename regex rule %s", groups[start_index]);
                    break;
                }